package com.dingwei.superiordiary.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.bean.SetStateBean;
import com.dingwei.superiordiary.mvp.presenter.NotifySetPresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author 南柯一梦丶
 * Created time 2018/10/22.
 * Personal signature 余生还长 何必慌张
 * Page description :
 * .::::.
 * .::::::::.
 * :::::::::::
 * ..:::::::::::'
 * '::::::::::::'
 * .::::::::::
 * '::::::::::::::..
 * ..::::::::::::.
 * ``::::::::::::::::
 * ::::``:::::::::'        .:::.
 * ::::'   ':::::'       .::::::::.
 * .::::'      ::::     .:::::::'::::.
 * .:::'       :::::  .:::::::::' ':::::.
 * .::'        :::::.:::::::::'      ':::::.
 * .::'         ::::::::::::::'         ``::::.
 * ...:::           ::::::::::::'              ``::.
 * ```` ':.          ':::::::::'                  ::::..
 * '.:::::'                    ':'````..
 */
public class NotifySetActivity extends BaseActivity implements Contract.NotifySetView {

    NotifySetPresenter notifySetPresenter = new NotifySetPresenter(this);
    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.img_call)
    ImageView imgCall;
    @Bind(R.id.img_comment)
    ImageView imgComment;
    @Bind(R.id.img_praise)
    ImageView imgPraise;
    @Bind(R.id.img_follow)
    ImageView imgFollow;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_notify_set;
    }

    @Override
    protected void initData() {
        notifySetPresenter.initData();
    }

    @Override
    protected void initView() {
        tvTitle.setText("通知设置");
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.img_back, R.id.img_call, R.id.img_comment, R.id.img_praise, R.id.img_follow, R.id.black_layout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.img_call:
                if (bean.data.strange_notice_call.equals("1")) {
                    bean.data.strange_notice_call = "0";
                } else {
                    bean.data.strange_notice_call = "1";
                }
                notifySetPresenter.noticeSetting(bean.data.strange_notice_call, bean.data.strange_notice_comment, bean.data.strange_notice_praise, bean.data.strange_notice_follow);
                break;
            case R.id.img_comment:
                if (bean.data.strange_notice_comment.equals("1")) {
                    bean.data.strange_notice_comment = "0";
                } else {
                    bean.data.strange_notice_comment = "1";
                }
                notifySetPresenter.noticeSetting(bean.data.strange_notice_call, bean.data.strange_notice_comment, bean.data.strange_notice_praise, bean.data.strange_notice_follow);
                break;
            case R.id.img_praise:
                if (bean.data.strange_notice_praise.equals("1")) {
                    bean.data.strange_notice_praise = "0";
                } else {
                    bean.data.strange_notice_praise = "1";
                }
                notifySetPresenter.noticeSetting(bean.data.strange_notice_call, bean.data.strange_notice_comment, bean.data.strange_notice_praise, bean.data.strange_notice_follow);
                break;
            case R.id.img_follow:
                if (bean.data.strange_notice_follow.equals("1")) {
                    bean.data.strange_notice_follow = "0";
                } else {
                    bean.data.strange_notice_follow = "1";
                }
                notifySetPresenter.noticeSetting(bean.data.strange_notice_call, bean.data.strange_notice_comment, bean.data.strange_notice_praise, bean.data.strange_notice_follow);
                break;
            case R.id.black_layout:
                intent = new Intent(BaseActivity.context, BlackListActivity.class);
                startActivity(intent);
                break;
        }
    }

    SetStateBean bean;

    @Override
    public void setData(SetStateBean bean) {
        this.bean = bean;
        if (bean.data.strange_notice_call.equals("1")) {
            imgCall.setImageResource(R.mipmap.ic_set_open);
        } else {
            imgCall.setImageResource(R.mipmap.ic_set_close);
        }
        if (bean.data.strange_notice_comment.equals("1")) {
            imgComment.setImageResource(R.mipmap.ic_set_open);
        } else {
            imgComment.setImageResource(R.mipmap.ic_set_close);
        }
        if (bean.data.strange_notice_praise.equals("1")) {
            imgPraise.setImageResource(R.mipmap.ic_set_open);
        } else {
            imgPraise.setImageResource(R.mipmap.ic_set_close);
        }
        if (bean.data.strange_notice_follow.equals("1")) {
            imgFollow.setImageResource(R.mipmap.ic_set_open);
        } else {
            imgFollow.setImageResource(R.mipmap.ic_set_close);
        }
    }

    @Override
    public void noticeSettingSuccess() {
        notifySetPresenter.initData();
    }
}
